home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-1.iso / math / ast51src.zip / XCHARTS2.C < prev    next >
C/C++ Source or Header  |  1995-12-31  |  20KB  |  542 lines

  1. /*
  2. ** Astrolog (Version 5.10) File: xcharts2.c
  3. **
  4. ** IMPORTANT NOTICE: The graphics database and chart display routines
  5. ** used in this program are Copyright (C) 1991-1995 by Walter D. Pullen
  6. ** (Astara@msn.com). Permission is granted to freely use and
  7. ** distribute these routines provided one doesn't sell, restrict, or
  8. ** profit from them in any way. Modification is allowed provided these
  9. ** notices remain with any altered or edited versions of the program.
  10. **
  11. ** The main planetary calculation routines used in this program have
  12. ** been Copyrighted and the core of this program is basically a
  13. ** conversion to C of the routines created by James Neely as listed in
  14. ** Michael Erlewine's 'Manual of Computer Programming for Astrologers',
  15. ** available from Matrix Software. The copyright gives us permission to
  16. ** use the routines for personal use but not to sell them or profit from
  17. ** them in any way.
  18. **
  19. ** The PostScript code within the core graphics routines are programmed
  20. ** and Copyright (C) 1992-1993 by Brian D. Willoughby
  21. ** (brianw@sounds.wa.com). Conditions are identical to those above.
  22. **
  23. ** The extended accurate ephemeris databases and formulas are from the
  24. ** calculation routines in the program "Placalc" and are programmed and
  25. ** Copyright (C) 1989,1991,1993 by Astrodienst AG and Alois Treindl
  26. ** (alois@azur.ch). The use of that source code is subject to
  27. ** regulations made by Astrodienst Zurich, and the code is not in the
  28. ** public domain. This copyright notice must not be changed or removed
  29. ** by any user of this program.
  30. **
  31. ** Initial programming 8/28,30, 9/10,13,16,20,23, 10/3,6,7, 11/7,10,21/1991.
  32. ** X Window graphics initially programmed 10/23-29/1991.
  33. ** PostScript graphics initially programmed 11/29-30/1992.
  34. ** Last code change made 12/27/1995.
  35. */
  36.  
  37. #include "astrolog.h"
  38.  
  39.  
  40. #ifdef GRAPH
  41. /*
  42. ******************************************************************************
  43. ** Chart Graphics Utility Procedures.
  44. ******************************************************************************
  45. */
  46.  
  47. /* Return whether the specified object should be displayed in the current */
  48. /* graphics chart type. For example, don't include the Moon in the solar  */
  49. /* system charts, don't include house cusps in astro-graph, and so on.    */
  50.  
  51. bool FProper(i)
  52. int i;
  53. {
  54.   bool f;
  55.  
  56.   if (gi.nMode == gHorizon || fMap || gi.nMode == gGlobe ||
  57.     gi.nMode == gPolar)                       /* Horizon and map charts */
  58.     f = FObject(i);
  59.   else if (gi.nMode == gOrbit)                /* Solar system charts */
  60.     f = FObject(i) && (i != oMoo || (us.fPlacalc && us.objCenter < oMoo));
  61.   else if (gi.nMode == gEphemeris)
  62.     f = FThing(i);                            /* Ephemeris charts */
  63.   else
  64.     f = fTrue;
  65.   return f && !ignore[i];                     /* Check restriction status */
  66. }
  67.  
  68.  
  69. /* Adjust an array of zodiac positions so that no two positions are within   */
  70. /* a certain orb of each other. This is used by the wheel drawing chart      */
  71. /* routines in order to make sure that we don't draw any planet glyphs on    */
  72. /* top of each other. We'll later draw the glyphs at the adjusted positions. */
  73.  
  74. void FillSymbolRing(symbol)
  75. real *symbol;
  76. {
  77.   real orb = DEFORB*256.0/(real)gs.yWin*(real)gi.nScale, k1, k2, temp;
  78.   int i, j, k = 1, l;
  79.  
  80.   /* Keep adjusting as long as we can still make changes, or until we do 'n' */
  81.   /* rounds. (With many objects, there just may not be enough room for all.) */
  82.  
  83.   for (l = 0; k && l < us.nDivision*2; l++) {
  84.     k = 0;
  85.     for (i = 1; i <= cObj; i++) if (FProper(i)) {
  86.  
  87.       /* For each object, determine who is closest on either side. */
  88.  
  89.       k1 = rLarge; k2 = -rLarge;
  90.       for (j = 1; j <= cObj; j++)
  91.         if (FProper(j) && i != j) {
  92.           temp = symbol[j]-symbol[i];
  93.           if (RAbs(temp) > rDegHalf)
  94.             temp -= rDegMax*RSgn(temp);
  95.           if (temp < k1 && temp > 0.0)
  96.             k1 = temp;
  97.           else if (temp > k2 && temp <= 0.0)
  98.             k2 = temp;
  99.         }
  100.  
  101.       /* If an object's too close on one side, then we move to the other. */
  102.  
  103.       if (k2 > -orb && k1 > orb) {
  104.         k = 1; symbol[i] = Mod(symbol[i]+orb*0.51+k2*0.49);
  105.       } else if (k1 < orb && k2 < -orb) {
  106.         k = 1; symbol[i] = Mod(symbol[i]-orb*0.51+k1*0.49);
  107.  
  108.       /* If we are bracketed by close objects on both sides, then let's move */
  109.       /* to the midpoint, so we are as far away as possible from either one. */
  110.  
  111.       } else if (k2 > -orb && k1 < orb) {
  112.         k = 1; symbol[i] = Mod(symbol[i]+(k1+k2)*0.5);
  113.       }
  114.     }
  115.   }
  116. }
  117.  
  118.  
  119. /* Adjust an array of longitude positions so that no two are within a    */
  120. /* certain orb of each other. This is used by the astro-graph routine to */
  121. /* make sure we don't draw any planet glyphs marking the lines on top of */
  122. /* each other. This is almost identical to the FillSymbolRing() routine  */
  123. /* used by the wheel charts; however, there the glyphs are placed in a   */
  124. /* continuous ring, while here we have the left and right screen edges.  */
  125. /* Also, here we are placing two sets of planets at the same time.       */
  126.  
  127. void FillSymbolLine(symbol)
  128. real *symbol;
  129. {
  130.   real orb = DEFORB*1.35*(real)gi.nScale, max = rDegMax, k1, k2, temp;
  131.   int i, j, k = 1, l;
  132.  
  133.   if (gi.nMode != gEphemeris)
  134.     max *= (real)gi.nScale;
  135.   else
  136.     orb *= rDegMax/(real)gs.xWin;
  137.  
  138.   /* Keep adjusting as long as we can still make changes. */
  139.  
  140.   for (l = 0; k && l < us.nDivision*2; l++) {
  141.     k = 0;
  142.     for (i = 1; i <= cObj*2; i++)
  143.       if (FProper((i+1)/2) && symbol[i] >= 0.0) {
  144.  
  145.         /* For each object, determine who is closest to the left and right. */
  146.  
  147.         k1 = max-symbol[i]; k2 = -symbol[i];
  148.         for (j = 1; j <= cObj*2; j++) {
  149.           if (FProper((j+1)/2) && i != j) {
  150.             temp = symbol[j]-symbol[i];
  151.             if (temp < k1 && temp > 0.0)
  152.               k1 = temp;
  153.             else if (temp > k2 && temp <= 0.0)
  154.               k2 = temp;
  155.           }
  156.         }
  157.  
  158.         /* If an object's too close on one side, then we move to the other. */
  159.  
  160.         if (k2 > -orb && k1 > orb) {
  161.           k = 1; symbol[i] = symbol[i]+orb*0.51+k2*0.49;
  162.         } else if (k1 < orb && k2 < -orb) {
  163.           k = 1; symbol[i] = symbol[i]-orb*0.51+k1*0.49;
  164.         } else if (k2 > -orb && k1 < orb) {
  165.           k = 1; symbol[i] = symbol[i]+(k1+k2)*0.5;
  166.         }
  167.       }
  168.   }
  169. }
  170.  
  171.  
  172. /* Given a zodiac degree, adjust it if need be to account for the expanding */
  173. /* and compacting of parts the zodiac that happen when we display a graphic */
  174. /* wheel chart such that all the houses appear the same size.               */
  175.  
  176. real HousePlaceInX(deg)
  177. real deg;
  178. {
  179.   int in;
  180.  
  181.   if (gi.nMode == gWheel)    /* We only adjust for the -w -X combination. */
  182.     return deg;
  183.   in = HousePlaceIn(deg);
  184.   return Mod(ZFromS(in)+MinDistance(house[in], deg)/
  185.     MinDistance(house[in], house[Mod12(in+1)])*30.0);
  186. }
  187.  
  188.  
  189. /*
  190. ******************************************************************************
  191. ** Multiple Chart Graphics Routines.
  192. ******************************************************************************
  193. */
  194.  
  195. /* Draw another wheel chart; however, this time we have two rings of planets */
  196. /* because we are doing a relationship chart between two sets of data. This  */
  197. /* chart is obtained when the -r0 is combined with the -X switch.            */
  198.  
  199. void XChartWheelRelation()
  200. {
  201.   real xsign[cSign+1], xhouse1[cSign+1], xplanet1[objMax], xplanet2[objMax],
  202.     symbol[objMax];
  203.   int cx, cy, i, j;
  204.   real asc, unitx, unity, px, py, temp;
  205.  
  206.   /* Set up variables and temporarily automatically decrease the horizontal */
  207.   /* chart size to leave room for the sidebar if that mode is in effect.    */
  208.  
  209.   if (gs.fText && !us.fVelocity)
  210.     gs.xWin -= xSideT;
  211.   cx = gs.xWin/2 - 1; cy = gs.yWin/2 - 1;
  212.   unitx = (real)cx; unity = (real)cy;
  213.   asc = gs.objLeft ? cp1.obj[abs(gs.objLeft)]+90*(gs.objLeft < 0) :
  214.     cp1.cusp[1];
  215.  
  216.   /* Fill out arrays with the degree of each object, cusp, and sign glyph. */
  217.  
  218.   if (gi.nMode == gWheel) {
  219.     for (i = 1; i <= cSign; i++)
  220.       xhouse1[i] = PZ(cp1.cusp[i]);
  221.   } else {
  222.     asc -= cp1.cusp[1];
  223.     for (i = 1; i <= cSign; i++)
  224.       xhouse1[i] = PZ(ZFromS(i));
  225.   }
  226.   for (i = 1; i <= cSign; i++)
  227.     xsign[i] = PZ(HousePlaceInX(ZFromS(i)));
  228.   for (i = 1; i <= cObj; i++)
  229.     xplanet1[i] = PZ(HousePlaceInX(cp1.obj[i]));
  230.   for (i = 1; i <= cObj; i++)
  231.     xplanet2[i] = PZ(HousePlaceInX(cp2.obj[i]));
  232.  
  233.   /* Draw the horizon and meridian lines across whole chart, and draw the */
  234.   /* zodiac and house rings, exactly like before. We are drawing only the */
  235.   /* houses of one of the two charts in the relationship, however.        */
  236.  
  237.   DrawColor(gi.kiLite);
  238.   DrawDash(cx+POINT1(unitx, 0.99, PX(xhouse1[sAri])),
  239.            cy+POINT1(unity, 0.99, PY(xhouse1[sAri])),
  240.            cx+POINT1(unitx, 0.99, PX(xhouse1[sLib])),
  241.            cy+POINT1(unity, 0.99, PY(xhouse1[sLib])), !gs.fColor);
  242.   DrawDash(cx+POINT1(unitx, 0.99, PX(xhouse1[sCap])),
  243.            cy+POINT1(unity, 0.99, PY(xhouse1[sCap])),
  244.            cx+POINT1(unitx, 0.99, PX(xhouse1[sCan])),
  245.            cy+POINT1(unity, 0.99, PY(xhouse1[sCan])), !gs.fColor);
  246.   for (i = 0; i < nDegMax; i += 5-(gs.fColor || gs.fPS || gs.fMeta)*4) {
  247.     temp = PZ(HousePlaceInX((real)i));
  248.     px = PX(temp); py = PY(temp);
  249.     DrawColor(i%5 ? gi.kiGray : gi.kiOn);
  250.     DrawDash(cx+POINT1(unitx, 0.78, px), cy+POINT1(unity, 0.78, py),
  251.       cx+POINT2(unitx, 0.82, px), cy+POINT2(unity, 0.82, py),
  252.       ((gs.fPS || gs.fMeta) && i%5)*2);
  253.   }
  254.  
  255.   DrawColor(gi.kiOn);
  256.   DrawCircle(cx, cy, (int)(unitx*0.95+rRound), (int)(unity*0.95+rRound));
  257.   DrawCircle(cx, cy, (int)(unitx*0.82+rRound), (int)(unity*0.82+rRound));
  258.   DrawCircle(cx, cy, (int)(unitx*0.78+rRound), (int)(unity*0.78+rRound));
  259.   DrawCircle(cx, cy, (int)(unitx*0.70+rRound), (int)(unity*0.70+rRound));
  260.  
  261.   for (i = 1; i <= cSign; i++) {
  262.     temp = xsign[i];
  263.     DrawColor(gi.kiOn);
  264.     DrawLine(cx+POINT2(unitx, 0.95, PX(temp)),
  265.       cy+POINT2(unity, 0.95, PY(temp)),
  266.       cx+POINT1(unitx, 0.82, PX(temp)),
  267.       cy+POINT1(unity, 0.82, PY(temp)));
  268.     DrawLine(cx+POINT2(unitx, 0.78, PX(xhouse1[i])),
  269.       cy+POINT2(unity, 0.78, PY(xhouse1[i])),
  270.       cx+POINT1(unitx, 0.70, PX(xhouse1[i])),
  271.       cy+POINT1(unity, 0.70, PY(xhouse1[i])));
  272.     if (gs.fColor && i%3 != 1) {
  273.       DrawColor(gi.kiGray);
  274.       DrawDash(cx, cy, cx+POINT1(unitx, 0.70, PX(xhouse1[i])),
  275.         cy+POINT1(unity, 0.70, PY(xhouse1[i])), 1);
  276.     }
  277.     temp = Midpoint(temp, xsign[Mod12(i+1)]);
  278.     DrawColor(kSignB(i));
  279.     DrawSign(i, cx+POINT1(unitx, 0.885, PX(temp)),
  280.       cy+POINT1(unity, 0.885, PY(temp)));
  281.     temp = Midpoint(xhouse1[i], xhouse1[Mod12(i+1)]);
  282.     DrawHouse(i, cx+POINT1(unitx, 0.74, PX(temp)),
  283.       cy+POINT1(unity, 0.74, PY(temp)));
  284.   }
  285.  
  286.   /* Draw the outer ring of planets (based on the planets in the chart     */
  287.   /* which the houses do not reflect - the houses belong to the inner ring */
  288.   /* below). Draw each glyph, a line from it to its actual position point  */
  289.   /* in the outer ring, and then draw another line from this point to a    */
  290.   /* another dot at the same position in the inner ring as well.           */
  291.  
  292.   for (i = 1; i <= cObj; i++)
  293.     symbol[i] = xplanet2[i];
  294.   FillSymbolRing(symbol);
  295.   for (i = cObj; i >= 1; i--) if (FProper2(i)) {
  296.     if (gs.fLabel) {
  297.       temp = symbol[i];
  298.       DrawColor(cp2.dir[i] < 0.0 ? gi.kiGray : gi.kiOn);
  299.       DrawDash(cx+POINT1(unitx, 0.58, PX(xplanet2[i])),
  300.         cy+POINT1(unity, 0.58, PY(xplanet2[i])),
  301.         cx+POINT2(unitx, 0.61, PX(temp)),
  302.         cy+POINT2(unity, 0.61, PY(temp)),
  303.         (cp2.dir[i] < 0.0 ? 1 : 0) - gs.fColor);
  304.       DrawObject(i, cx+POINT1(unitx, 0.65, PX(temp)),
  305.         cy+POINT1(unity, 0.65, PY(temp)));
  306.     }
  307.     DrawColor(kObjB[i]);
  308.     DrawPoint(cx+POINT1(unitx, 0.56, PX(xplanet2[i])),
  309.       cy+POINT1(unity, 0.56, PY(xplanet2[i])));
  310.     DrawPoint(cx+POINT1(unitx, 0.43, PX(xplanet2[i])),
  311.       cy+POINT1(unity, 0.43, PY(xplanet2[i])));
  312.     DrawColor(cp2.dir[i] < 0.0 ? gi.kiGray : gi.kiOn);
  313.     DrawDash(cx+POINT1(unitx, 0.45, PX(xplanet2[i])),
  314.       cy+POINT1(unity, 0.45, PY(xplanet2[i])),
  315.       cx+POINT2(unitx, 0.54, PX(xplanet2[i])),
  316.       cy+POINT2(unity, 0.54, PY(xplanet2[i])), 2-gs.fColor);
  317.   }
  318.  
  319.   /* Now draw the inner ring of planets. If it weren't for the outer ring,  */
  320.   /* this would be just like the standard non-relationship wheel chart with */
  321.   /* only one set of planets. Again, draw glyph, and a line to true point.  */
  322.  
  323.   for (i = 1; i <= cObj; i++)
  324.     symbol[i] = xplanet1[i];
  325.   FillSymbolRing(symbol);
  326.   for (i = 1; i <= cObj; i++) if (FProper(i)) {
  327.     if (gs.fLabel) {
  328.       temp = symbol[i];
  329.       DrawColor(cp1.dir[i] < 0.0 ? gi.kiGray : gi.kiOn);
  330.       DrawDash(cx+POINT1(unitx, 0.45, PX(xplanet1[i])),
  331.         cy+POINT1(unity, 0.45, PY(xplanet1[i])),
  332.         cx+POINT2(unitx, 0.48, PX(temp)),
  333.         cy+POINT2(unity, 0.48, PY(temp)),
  334.         (cp1.dir[i] < 0.0 ? 1 : 0) - gs.fColor);
  335.       DrawObject(i, cx+POINT1(unitx, 0.52, PX(temp)),
  336.         cy+POINT1(unity, 0.52, PY(temp)));
  337.     } else
  338.       DrawColor(kObjB[i]);
  339.     DrawPoint(cx+POINT1(unitx, 0.43, PX(xplanet1[i])),
  340.       cy+POINT1(unity, 0.43, PY(xplanet1[i])));
  341.   }
  342.  
  343.   /* Draw lines connecting planets between the two charts that have aspects. */
  344.  
  345.   if (!gs.fAlt) {                      /* Don't draw aspects in bonus mode. */
  346.     if (!FCreateGridRelation(fFalse))
  347.       return;
  348.     for (j = cObj; j >= 1; j--)
  349.       for (i = cObj; i >= 1; i--)
  350.         if (grid->n[i][j] && FProper2(i) && FProper(j)) {
  351.           DrawColor(kAspB[grid->n[i][j]]);
  352.           DrawDash(cx+POINT1(unitx, 0.41, PX(xplanet1[j])),
  353.             cy+POINT1(unity, 0.41, PY(xplanet1[j])),
  354.             cx+POINT1(unitx, 0.41, PX(xplanet2[i])),
  355.             cy+POINT1(unity, 0.41, PY(xplanet2[i])),
  356.             abs(grid->v[i][j]/60/2));
  357.         }
  358.   }
  359.  
  360.   /* Go draw sidebar with chart information and positions if need be. */
  361.  
  362.   DrawInfo();
  363. }
  364.  
  365.  
  366. /* Draw an aspect (or midpoint) grid in the window, between the planets in  */
  367. /* two different charts, with the planets labeled at the top and side. This */
  368. /* chart is done when the -g switch is combined with the -r0 and -X switch. */
  369. /* Like above, the chart always has a (definable) fixed number of cells.    */
  370.  
  371. void XChartGridRelation()
  372. {
  373.   char sz[cchSzDef];
  374.   int unit, siz, x, y, i, j, k, l;
  375.   KI c;
  376.  
  377.   unit = CELLSIZE*gi.nScale; siz = (gs.nGridCell+1)*unit;
  378.   if (!FCreateGridRelation(gs.fAlt != us.fGridConfig))
  379.     return;
  380.   for (y = 0, j = -1; y <= gs.nGridCell; y++) {
  381.     do {
  382.       j++;
  383.     } while (ignore[j] && j <= cObj);
  384.     DrawColor(gi.kiGray);
  385.     DrawDash(0, (y+1)*unit, siz, (y+1)*unit, !gs.fColor);
  386.     DrawDash((y+1)*unit, 0, (y+1)*unit, siz, !gs.fColor);
  387.     DrawColor(gi.kiLite);
  388.     DrawEdge(0, y*unit, unit, (y+1)*unit);
  389.     DrawEdge(y*unit, 0, (y+1)*unit, unit);
  390.     if (j <= cObj) for (x = 0, i = -1; x <= gs.nGridCell; x++) {
  391.       do {
  392.         i++;
  393.       } while (ignore[i] && i <= cObj);
  394.  
  395.       /* Again, we are looping through each cell in each row and column. */
  396.  
  397.       if (i <= cObj) {
  398.         gi.xTurtle = x*unit+unit/2;
  399.         gi.yTurtle = y*unit+unit/2 -
  400.           (gi.nScale/gi.nScaleT > 2 ? 5*gi.nScaleT : 0);
  401.         k = grid->n[i][j];
  402.  
  403.         /* If current cell is on top row or left hand column, draw glyph */
  404.         /* of planet owning the particular row or column in question.    */
  405.  
  406.         if (y == 0 || x == 0) {
  407.           if (x+y > 0)
  408.             DrawObject(j == 0 ? i : j, gi.xTurtle, gi.yTurtle);
  409.         } else {
  410.  
  411.         /* Otherwise, draw glyph of aspect in effect, or glyph of */
  412.         /* sign of midpoint, between the two planets in question. */
  413.  
  414.           if (gs.fAlt == us.fGridConfig) {
  415.             if (k) {
  416.               DrawColor(c = kAspB[k]);
  417.               DrawAspect(k, gi.xTurtle, gi.yTurtle);
  418.             }
  419.           } else {
  420.             DrawColor(c = kSignB(grid->n[i][j]));
  421.             DrawSign(grid->n[i][j], gi.xTurtle, gi.yTurtle);
  422.           }
  423.         }
  424.  
  425.         /* Again, when scale size is 300+, print some text in current cell: */
  426.  
  427.         if (gi.nScale/gi.nScaleT > 2 && gs.fLabel) {
  428.  
  429.           /* For top and left edges, print sign and degree of the planet. */
  430.  
  431.           if (y == 0 || x == 0) {
  432.             if (x+y > 0) {
  433.               k = SFromZ(y == 0 ? cp2.obj[i] : cp1.obj[j]);
  434.               l = (int)((y == 0 ? cp2.obj[i] : cp1.obj[j])-ZFromS(k));
  435.               c = kSignB(k);
  436.               sprintf(sz, "%c%c%c %02d", chSig3(k), l);
  437.  
  438.               /* For extreme upper left corner, print some little arrows */
  439.               /* pointing out chart1's planets and chart2's planets.     */
  440.  
  441.             } else {
  442.               c = gi.kiLite;
  443.               sprintf(sz, "1v 2->");
  444.             }
  445.           } else {
  446.             k = abs(grid->v[i][j]);
  447.  
  448.             /* For aspect cells, print the orb in degrees and minutes. */
  449.  
  450.             if (gs.fAlt == us.fGridConfig) {
  451.               if (grid->n[i][j])
  452.                 sprintf(sz, "%c%d %02d'", k != grid->v[i][j] ?
  453.                   (us.fAppSep ? 'a' : '-') : (us.fAppSep ? 's' : '+'),
  454.                   k/60, k%60);
  455.               else
  456.                 sprintf(sz, "");
  457.  
  458.             /* For midpoint cells, print degree and minute. */
  459.  
  460.             } else
  461.               sprintf(sz, "%2d %02d'", k/60, k%60);
  462.           }
  463.           DrawColor(c);
  464.           DrawSz(sz, x*unit+unit/2, (y+1)*unit-3*gi.nScaleT, dtBottom);
  465.         }
  466.       }
  467.     }
  468.   }
  469. }
  470.  
  471.  
  472. #ifdef BIORHYTHM
  473. /* Draw a graphic biorhythm chart on the screen, as is done when the -rb    */
  474. /* switch is combined with -X. This is technically a relationship chart in  */
  475. /* that biorhythm status is determined by a natal chart time at another     */
  476. /* later time. For the day in question, and for two weeks before and after, */
  477. /* the Physical, Emotional, and Mental percentages are plotted.             */
  478.  
  479. void XChartBiorhythm()
  480. {
  481.   char sz[6], *c;
  482.   real jd, r, a;
  483.   int x1, x2, xs, cx, y1, y2, ys, cy, i, j, k, x, y, x0, y0;
  484.  
  485.   k = xFont*6*gi.nScaleT;
  486.   x1 = k; x2 = gs.xWin-k; xs = x2-x1; cx = (x1+x2)/2;
  487.   k = CELLSIZE;
  488.   y1 = k; y2 = gs.yWin-k; ys = y2-y1; cy = (y1+y2)/2;
  489.  
  490.   /* Create a dotted day/percentage grid to graph on. */
  491.   DrawColor(gi.kiGray);
  492.   DrawDash(x1, cy, x2, cy, 1);
  493.   DrawDash(cx, y1, cx, y2, 1);
  494.   for (j = -BIODAYS+1; j <= BIODAYS-1; j++) {
  495.     x = x1 + NMultDiv(xs, j+BIODAYS, BIODAYS*2);
  496.     for (k = -90; k <= 90; k += 10) {
  497.       y = y1 + NMultDiv(ys, 100+k, 200);
  498.       DrawPoint(x, y);
  499.     }
  500.   }
  501.  
  502.   /* Now actually draw the three biorhythm curves. */
  503.   for (i = 1; i <= 3; i++) {
  504.     jd = RFloor(is.JD + rRound);
  505.     switch (i) {
  506.     case 1: r = brPhy; c = "PHYS"; j = eFir; break;
  507.     case 2: r = brEmo; c = "EMOT"; j = eWat; break;
  508.     case 3: r = brInt; c = "INTE"; j = eEar; break;
  509.     }
  510.     DrawColor(kElemB[j]);
  511.     for (jd -= (real)BIODAYS, j = -BIODAYS; j <= BIODAYS; j++, jd += 1.0) {
  512.       a = RBiorhythm(jd, r);
  513.       x = x1 + NMultDiv(xs, j+BIODAYS, BIODAYS*2);
  514.       y = y1 + (int)((real)ys * (100.0-a) / 200.0);
  515.       if (j > -BIODAYS)
  516.         DrawLine(x0, y0, x, y);
  517.       else
  518.         DrawSz(c, x1/2, y+2*gi.nScaleT, dtCent);
  519.       x0 = x; y0 = y;
  520.     }
  521.   }
  522.  
  523.   DrawColor(gi.kiLite);
  524.   /* Label biorhythm percentages along right vertical axis. */
  525.   for (k = -100; k <= 100; k += 10) {
  526.     sprintf(sz, "%c%3d%%", k < 0 ? '-' : '+', abs(k));
  527.     y = y1 + NMultDiv(ys, 100-k, 200);
  528.     DrawSz(sz, (x2+gs.xWin)/2, y+2*gi.nScaleT, dtCent);
  529.   }
  530.   /* Label days on top horizontal axis. */
  531.   for (j = -BIODAYS+2; j < BIODAYS; j += 2) {
  532.     x = x1 + NMultDiv(xs, j+BIODAYS, BIODAYS*2);
  533.     sprintf(sz, "%c%d", j < 0 ? '-' : '+', abs(j));
  534.     DrawSz(sz, x, y1-2*gi.nScaleT, dtBottom);
  535.   }
  536.   DrawEdge(x1, y1, x2, y2);
  537. }
  538. #endif /* BIORHYTHM */
  539. #endif /* GRAPH */
  540.  
  541. /* xcharts2.c */
  542.